<link rel="stylesheet" href="${baseStaticUrl}/plugins/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript" src="${baseStaticUrl}/plugins/ztree/js/jquery.ztree.core.js"></script>
<script type="text/javascript" src="${baseStaticUrl}/plugins/ztree/js/jquery.ztree.excheck.js"></script>
<div class="form-container">
	<div class="box">
        <form action="#" method="post" name="suvForm" id="suvForm">
        	<div class="row visa-row">
                <div id="wait-msg" class="alert alert-info"
                     style="background:url(${baseStaticUrl}/images/ajax-loader.gif) no-repeat scroll 0.5em 50%;display:none"></div>
                <div id="alert-msg" class="alert alert-success" style="display:none"></div>
                <div id="error-msg" class="alert alert-danger" style="display:none"></div>
            </div>
            <div class="row visa-row">
            	<h6 class="mg-b-20 h6-mar-sm">
                    <strong>数据字典管理</strong>
                </h6>
                <div class="row w-row">
                	<div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span>字典编码</div>
					<div class="col-md-3 col-xs-12 w-row2"><input type="text" id="zdbm" onchange="checkDictCode()"
						class="form-control form-control-sm" name="sysDict.DICT_CODE"
						@if(sysDict.DICT_CODE !=null){
						readonly="readonly"
						@}
						value="${sysDict.DICT_CODE}"> <input type="hidden"
						id="ID" class="form-control cos-md-4" name="sysDict.ID"
						value="${sysDict.ID}"></div>
					<div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span>字典名称</div>
					<div class="col-md-3 col-xs-12 w-row2"><input type="text" id="zdmc" onchange="checkDictName()"
									class="form-control form-control-sm" name="sysDict.DICT_NAME"
									value="${sysDict.DICT_NAME}"></div>
					<div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span>是否启用</div>
					<div class="col-md-3 col-xs-12 w-row2">
						<epoch:radio name="sysDict.DICT_FLAG" id="zdsfqy" list="${lisFun.getDictCode('PUB_Y_N')}"
	                      			checked="${sysDict.DICT_FLAG!'Y'}"></epoch:radio>
					</div> 
                </div>
                <div class="row w-row">
                     <div class="col-md-1 col-xs-12 w-row1"><span class="span_red">*</span>字典描述</div>
					 <div class="col-md-11 col-xs-12 w-row2">
                                 <textarea rows="4" cols="129" style="width: 98%;resize: none;" id="zdms" maxlength="255" name="sysDict.DICT_COMMENTS">${sysDict.DICT_COMMENTS}</textarea>
					</div>
				</div>
            </div>
        </form>
    </div>
    <div class="box">
    	<div class="row visa-row range">
            <epoch:table id="sysDictItemTable" rowId="id" tableName="字典项信息"
                queryUrl="${basePath}/sys/dict/findSysDictItemListAjax?dict_code=${sysDict.DICT_CODE!}" showRefresh="true"
                editable="true" onSaveEdit="saveEdit" saveBtn="false" cancelBtn="false" addRowBtn="true" delRowBtn="true">
                <epoch:tr check="checkbox" titleTip="epoch:tr'cmn_tip_checkAll'))}"></epoch:tr>
                <epoch:tr name="项编码" formName="item_code" width="20%"></epoch:tr>
                <epoch:tr name="项值" formName="item_value" editorType="custom-simple" width="20%">
                    ~{value}
                    <div class="editable-custom visa-btn-icon-inbox">
                        <input type="text" name="item_value" class="form-control form-control-sm" />
                    </div>
                </epoch:tr>
                <epoch:tr name="排序" formName="item_seq" editorType="custom-simple" width="10%">
                	~{value}
                    <div class="editable-custom visa-btn-icon-inbox">
                        <input type="number" name="item_seq" class="form-control form-control-sm" />
                    </div>
                </epoch:tr>
                <epoch:tr name="是否启用" formName="item_flag" filterType="select" editorType="custom-simple" width="10%" filterData="${lisFun.dictForFilter('PUB_Y_N')}">
                	~{value}
	                <span class="editable-custom" style="white-space:nowrap;">
	                       <epoch:select list="${lisFun.getDictCode('PUB_Y_N')}" class="form-control form-control-sm" 
	                            value="${item_flag!}" first="false" name="item_flag" id="item_flag~{index}">
	                        </epoch:select>
	                 </span>
                </epoch:tr>
                <epoch:tr name="字典项信息" formName="dic_comments" width="40%"></epoch:tr>
            </epoch:table>
	         <input id="curItemValIdx" type="hidden"/>
       </div>
    </div>
</div>
<script type="text/javascript">
	_headToolBar.saveBtn(null, null, suv);
    
    function suv(){
    	 //字典编码
        if ($("#zdbm").val() == null || $("#zdbm").val() == '') {
            showErrorMessage("error-msg","字典编码不能为空。");
            $("#zdbm").focus();
            return false;
        }
        //校验字典名称
        if ($("#zdmc").val() == null || $("#zdmc").val() == '') {
            showErrorMessage("error-msg","字典名称不能为空。");
            $("#zdmc").focus();
            return false;
        }
        // 字典是否启用
        var count = 0;
        $(":input[type='radio']").each(function(index, ele){
        	if(ele.checked){
        		count ++;
        	}
        });
        if (count == 0) {
            showErrorMessage("error-msg","是否启用不能为空。");
            $("#zdsfqy").focus();
            return false;
        }
        //字典描述
        if ($("#zdms").val() == null || $("#zdms").val() == '') {
            showErrorMessage("error-msg","字典描述不能为空。");
            $("#zdms").focus();
            return false;
        }
        var data = $("#sysDictItemTable").bootstrapTable("cer_confirmEditAllRows");
        $.ajax({
            url : "${basePath}/sys/dict/saveAll?"+$("form").serialize(), //路径
            type : "POST",
            data : {
                editData: data
            },
            success : function(data, status, jqXHR) {
            	MessageBox.success("保存成功！");
                _tabs.showPage("list");
            },
            error : function(jqXHR, status, errorInfo) {
            	MessageBox.error("保存失败！");
            }
        });
	}

</script>